<!--跨组件计算属性-->
<template>
    <div>
        <p>总库存:{{total_num}}</p>
        <div>
            <p><input type="number" v-model.number="input1"></p>
            <p><input type="number" v-model.number="input2"></p>
            <p>输入总数量:{{sum_input}}</p>

            <button @click="submit">提交</button>
        </div>
    </div>
</template>

<script>
    export default {
        name: "child",
        props: ['total_num'],
        data() {
            return {
                input1: 0,
                input2: 0,

            }
        },
        computed: {
            sum_input() {
                return this.input1 + this.input2
            }
        },
        methods: {
            submit() {
                this.$message(this.sum_input > this.total_num ? `您输入的数量大于库存数量 ${this.total_num}` : `提交成功！`)
            }
        }
    }
</script>

<style scoped>

</style>